<?php

namespace common\models\meeting;

use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
use common\models\category\Category;
use yii\helpers\ArrayHelper;
/**
 * This is the model class for table "meeting".
 *
 * @property integer $id
 * @property string $title
 * @property string $summary
 * @property string $content
 * @property string $label_img
 * @property string $beforeprompt
 * @property string $duringprompt
 * @property string $meetingdata
 * @property integer $is_valid
 * @property integer $created_at
 * @property integer $updated_at
 * @property string $starttime
 * @property string $endtime
 * @property string $schedule
 */
class Meeting extends \yii\db\ActiveRecord
{
    public $newimg;
    public $newfile;
	private $_isopenLabel;
	private $_ispayLabel;
	
	const IS_OPEN = 1;
    const NO_OPEN = 0;
	const IS_PAY = 1;
	const NO_PAY = 0;
	

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'meeting';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title', 'summary', 'content', 'category_id'], 'required'],
            [['content', 'schedule'], 'string'],
            [['is_pay', 'created_at', 'updated_at', 'category_id'], 'integer'],
            [['title', 'summary', 'label_img', 'beforeprompt', 'duringprompt', 'meetingdata', 'starttime', 'endtime', 'deadline'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'title' => Yii::t('app', '会议主题'),
            'category_id' => Yii::t('app', '分类'),
            'summary' => Yii::t('app', '摘要'),
            'content' => Yii::t('app', '内容'),
            'label_img' => Yii::t('app', '会场平面图'),
            'beforeprompt' => Yii::t('app', '会前提示'),
            'duringprompt' => Yii::t('app', '会中提示'),
            'meetingdata' => Yii::t('app', '会议资料'),
            'is_pay' => Yii::t('app', '支付'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
            'starttime' => Yii::t('app', '开始时间'),
            'endtime' => Yii::t('app', '结束时间'),
            'deadline' => Yii::t('app', '报名截止时间'),
            'schedule' => Yii::t('app', '会议日程'),
            'enroll' => Yii::t('app', '报名'),
        ];
    }
	
    public function getCategory()
    {
        return $this->hasOne(Category::className(), ['id' => 'category_id']);
    }
    
    public static function getArrayCategory()
    {
        return ArrayHelper::map(Category::find()->all(), 'id', 'name');
    }


    public static function findimg($modelimg){
       $img =  Yii::$app->params['meetingimg'] . json_decode($modelimg, true)['newname'];
       return $img;
    }
	
    public function getIsopenLabel()
    {
        if ($this->_isopenLabel === null) {
            $isopens = self::getArrayIsopen();
            $this->_isopenLabel = array_key_exists($this->enroll,self::getArrayIsopen()) ? $isopens[$this->enroll] : '无';
        }
        return $this->_isopenLabel;
    }
    /**
     * @inheritdoc
     */
    public static function getArrayIsopen()
    {
        return [
            self::IS_OPEN => Yii::t('app', '已开启'),
            self::NO_OPEN => Yii::t('app', '未开启'),
        ];
    }
	
	public function getIspayLabel()
	{
		if($this->_ispayLabel === null){
			$ispays = self::getArrayIspay();
			$this->_ispayLabel = array_key_exists($this->is_pay, self::getArrayIspay()) ? $ispays[$this->is_pay] : '无';
		}
		return $this->_ispayLabel;
	}
	public static function getArrayIspay()
	{
		return [
			self::IS_PAY => Yii::t('app', '启用'),
			self::NO_PAY => Yii::t('app', '停用'),
		];
	}
     public function getMeetingenroll()
{
    /**
    * 第一个参数为要关联的字表模型类名称，
    *第二个参数指定 通过子表的 customer_id 去关联主表的 id 字段
    */
    return $this->hasMany(Meetingenroll::className(), ['meeting_id' => 'id']);
}
   
	
	/**
	* 
	* 
	*/

}